--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_usami_renko = General:new(extension, "hy_usami_renko", "chi_k", 4, 4, General.Female)
    local explore_traces = fk.CreateSkill {
        name = "explore_traces",
    }
    explore_traces:addEffect(fk.GameStart, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(explore_traces.name)
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local skills = { "freak_report", "taboo_disentangment", "trojan_asteroid" }
            for _, name in pairs(player:getSkillNameList()) do
                table.removeOne(skills, name)
            end
            if #skills == 0 then
                return
            end
            local result = room:askToChoice(player, {
                choices = skills,
                prompt = "explore_traces_prompt",
                skill_name = explore_traces.name,
                cancelable = false,
            })
            room:handleAddLoseSkills(player, result)
        end
    })
    local freak_report = fk.CreateSkill {
        name = "freak_report",
        tags = {
            Skill.Limited
        }
    }
    freak_report:addEffect("active", {
        can_use = function(self, player)
            return player:usedSkillTimes(freak_report.name, Player.HistoryGame) < 1
        end,
        card_filter = Util.FalseFunc,
        target_filter = function(self, player, to_select, selected, selected_cards)
            local count = #player:getSkillNameList()
            if count <= 2 then
                return false
            elseif count >= 3 then
                return #selected == 0 and to_select:isWounded()
            end
        end,
        feasible = function(self, player, selected, selected_cards, card)
            local count = #player:getSkillNameList()
            if count <= 2 then
                return #selected == 0 and #selected_cards == 0
            elseif count >= 3 then
                return #selected == 1 and #selected_cards == 0
            end
        end,
        prompt = function(self, player, selected_cards, selected_targets)
            local count = #player:getSkillNameList()
            if count <= 2 then
                return "freak_report_prompt1"
            elseif count >= 3 then
                return "freak_report_prompt2"
            end
            return ""
        end,
        on_use = function(self, room, skillUseEvent)
            local player = skillUseEvent.from
            local count = #player:getSkillNameList()
            if count <= 2 then
                room:drawCards(player, 3, freak_report.name)
            elseif count >= 3 then
                room:drawCards(player, 4, freak_report.name)
                local target = skillUseEvent.tos[1]
                room:recover({
                    who = target,
                    num = 1,
                    skillName = freak_report.name,
                    recoverBy = player
                })
            end
            local e = room.logic:getCurrentEvent():findParent(GameEvent.Round, true)
            if e then
                e:addExitFunc(function()
                    room:useSkill(player, Fk.skills["explore_traces"], function()
                        for _, sk in pairs(explore_traces.effects) do
                            if sk:isInstanceOf(TriggerSkill) then
                                ---@cast sk TriggerSkill
                                sk:use(fk.GameStart, player, player)
                            end
                        end
                    end)
                end)
            end
        end
    })
    local taboo_disentangment = fk.CreateSkill {
        name = "taboo_disentangment",
        tags = {
            Skill.Wake,
        }
    }
    taboo_disentangment:addAcquireEffect(function(self, player, is_start)
        local room = player.room
        room:setPlayerMark(player, "taboo_disentangment", {})
        room:setPlayerMark(player, "@taboo_disentangment", 0)
    end)
    taboo_disentangment:addLoseEffect(function(self, player, is_start)
        local room = player.room
        room:setPlayerMark(player, "taboo_disentangment", {})
        room:setPlayerMark(player, "@taboo_disentangment", 0)
    end)
    taboo_disentangment:addEffect(fk.CardUseFinished, {
        can_refresh = function(self, event, target, player, data)
            return player:hasSkill(taboo_disentangment.name) and target == player and player:usedSkillTimes(taboo_disentangment.name, Player.HistoryGame) < 1
        end,
        on_refresh = function(self, event, target, player, data)
            local room = player.room
            local card = data.card
            local marks = player:getTableMark("taboo_disentangment")
            table.insertIfNeed(marks, card:getTypeString() .. "_char")
            room:setPlayerMark(player, "taboo_disentangment", marks)
            room:setPlayerMark(player, "@taboo_disentangment", marks)
        end
    })
    taboo_disentangment:addEffect(fk.EventPhaseStart, {
        can_trigger = function(self, event, target, player, data)
            return data.phase == Player.Finish and player:usedSkillTimes(taboo_disentangment.name, Player.HistoryGame) < 1
        end,
        can_wake = function(self, event, target, player, data)
            local cards = table.map(Fk:getAllCardIds(), function(id)
                return Fk:getCardById(id)
            end)
            local types = {}
            for _, card in pairs(cards) do
                table.insertIfNeed(types, card.type)
            end
            return #player:getTableMark("taboo_disentangment") == #types and target == player and player:hasSkill(taboo_disentangment.name)
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local count = #player:getSkillNameList()
            local targets = room:askToChoosePlayers(player, {
                targets = room:getAlivePlayers(),
                min_num = 1,
                max_num = 2,
                skill_name = taboo_disentangment.name,
                prompt = count <= 2 and "taboo_disentangment_prompt1" or "taboo_disentangment_prompt2",
            })
            if #targets == 0 then
                return
            end
            for _, t in pairs(targets) do
                t:turnOver()
                if count >= 3 then
                    room:throwCard(t:getCardIds("e"), taboo_disentangment.name, t, player)
                end
            end
            local e = room.logic:getCurrentEvent():findParent(GameEvent.Round, true)
            if e then
                e:addExitFunc(function()
                    room:useSkill(player, Fk.skills["explore_traces"], function()
                        for _, sk in pairs(explore_traces.effects) do
                            if sk:isInstanceOf(TriggerSkill) then
                                ---@cast sk TriggerSkill
                                sk:use(fk.GameStart, player, player)
                            end
                        end
                    end)
                end)
            end
        end,
    })
    local trojan_asteroid = fk.CreateSkill {
        name = "trojan_asteroid",
        tags = {
            Skill.Quest,
        }
    }
    trojan_asteroid:addEffect("viewas", {
        mute_card = false,
        pattern = ".",
        times = function(self, player)
            return 2 - player:usedEffectTimes(self.name, Player.HistoryRound)
        end,
        card_filter = function(self, player, to_select, selected)
            local card = Fk:getCardById(to_select)
            return #selected == 0 and not HY.IsCardPublicized(card) and (card.type == Card.TypeBasic or card:isCommonTrick())
        end,
        prompt = function(self, player, selected_cards, selected)
            return "trojan_asteroid_prompt"
        end,
        view_as = function(self, player, cards)
            if player:usedEffectTimes(self.name, Player.HistoryRound) >= 2 or player:getQuestSkillState(trojan_asteroid.name) ~= nil or #cards ~= 1 then
                return
            end
            local card = Fk:getCardById(cards[1])
            local result = Fk:cloneCard(card.name)
            player.tag["trojan_asteroid"] = card.id
            return result
        end,
        enabled_at_play = function(self, player)
            return player:usedEffectTimes(self.name, Player.HistoryRound) < 2 and player:getQuestSkillState(trojan_asteroid.name) == nil
        end,
        enabled_at_response = function(self, player, response)
            return player:usedEffectTimes(self.name, Player.HistoryRound) < 2 and player:getQuestSkillState(trojan_asteroid.name) == nil and not response
        end,
    })
    trojan_asteroid:addEffect(fk.PreCardUse, {
        can_refresh = function(self, event, target, player, data)
            return player.tag["trojan_asteroid"]
        end,
        on_refresh = function(self, event, target, player, data)
            local room = player.room
            local card = Fk:getCardById(player.tag["trojan_asteroid"])
            player.tag["trojan_asteroid"] = nil
            HY.SetCardPublicize(room, card)
        end
    })
    trojan_asteroid:addEffect(fk.Damaged, {
        can_refresh = function(self, event, target, player, data)
            return player:hasSkill(trojan_asteroid.name) and data.to == player and player:getQuestSkillState(trojan_asteroid.name) == nil
        end,
        on_refresh = function(self, event, target, player, data)
            player.room:setPlayerMark(player, "trojan_asteroid-round", 1)
        end
    })
    trojan_asteroid:addEffect(fk.RoundEnd, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(trojan_asteroid.name) and player:getQuestSkillState(trojan_asteroid.name) == nil and player:getMark("trojan_asteroid-round") == 0
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            room:updateQuestSkillState(player, trojan_asteroid.name, false)
            local count = #player:getSkillNameList()
            local card = Fk:cloneCard("savage_assault")
            local targets = table.filter(room:getOtherPlayers(player), function(t)
                return player:canUseTo(card, t)
            end)
            if count >= 3 then
                local cancel = room:askToChoosePlayers(player, {
                    targets = targets,
                    min_num = 1,
                    max_num = 1,
                    skill_name = trojan_asteroid.name,
                    prompt = "trojan_asteroid_prompt_cancel"
                })
                for _, t in ipairs(cancel) do
                    table.removeOne(targets, t)
                end
            end
            room:useCard({
                from = player,
                card = card,
                tos = targets,
                disresponsiveList = count >= 3 and room:getAlivePlayers() or {}
            })
            room:useSkill(player, Fk.skills["explore_traces"], function()
                for _, sk in pairs(explore_traces.effects) do
                    if sk:isInstanceOf(TriggerSkill) then
                        ---@cast sk TriggerSkill
                        sk:use(fk.GameStart, player, player)
                    end
                end
            end)
        end,
    })
    extension:loadSkillSkels { explore_traces, freak_report, taboo_disentangment, trojan_asteroid }
    hy_usami_renko:addSkill("explore_traces")
    hy_usami_renko:addRelatedSkills { "taboo_disentangment", "trojan_asteroid", "freak_report" }
    Fk:loadTranslationTable {
        ["hy_usami_renko"] = "宇佐见莲子",
        ["#hy_usami_renko"] = "理界学徒",
        ["designer:hy_usami_renko"] = "黑曜人形",
        ["illustrator:hy_usami_renko"] = "Rhea",
        ["cv:hy_usami_renko"] = "",

        ["explore_traces"] = "探迹",
        [":explore_traces"] = "游戏开始时，你从“<a href=':freak_report'>燕志</a>”，“<a href=':taboo_disentangment'>七坂</a>”，“<a href=':trojan_asteroid'>遗船</a>”中选择未拥有的一项获得之。",
        ["explore_traces_prompt"] = "探迹：获得一个技能",

        ["freak_report"] = "燕志",
        [":freak_report"] = "限定技，出牌阶段，你可以根据你的技能数执行对应效果：不大于2，摸三张牌；不小于3，摸四张牌并令一名角色回复1点体力。本轮结束时，你发动“探迹”。",
        ["freak_report_prompt1"] = "燕志：摸三张牌",
        ["freak_report_prompt2"] = "燕志：摸四张牌并令一名角色回复1点体力",

        ["taboo_disentangment"] = "七坂",
        [":taboo_disentangment"] = "觉醒技，结束阶段，若你获得此技能后使用过所有类型的牌，根据你的技能数执行对应效果：不大于2，令至多两名角色翻面；不小于3，令至多两名角色翻面并弃置其装备区所有牌。然后你于本轮结束时发动“探迹”。",
        ["@taboo_disentangment"] = "七坂",
        ["taboo_disentangment_prompt1"] = "七坂：令至多两名角色翻面",
        ["taboo_disentangment_prompt2"] = "七坂：令至多两名角色翻面并弃置其装备区所有牌",

        ["trojan_asteroid"] = "遗船",
        [":trojan_asteroid"] = "使命技，每轮限两次，你可以<a href = 'hy_card_publicize'>明置</a>一张基本牌或普通锦囊牌并视为使用之。<br>&nbsp;&nbsp;&nbsp;&nbsp;成功：每轮结束时，若你本轮未受到伤害，根据你的技能数执行对应效果：不大于2，视为使用【南蛮入侵】；不小于3，视为使用一张不可响应且可取消一个目标的【南蛮入侵】。然后你发动“探迹”。",
        ["trojan_asteroid_prompt"] = "遗船：明置一张基本牌或普通锦囊牌并视为使用之",
        ["trojan_asteroid_prompt_cancel"] = "遗船：你可以取消一个目标",
    }
end
